package pfc.view.view.components.view;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

public class ImagePanel extends JPanel {
	private BufferedImage image = null;

	public ImagePanel() {
//		try {
//			System.out.println("Enter image name\n");
//			BufferedReader bf = new BufferedReader(new InputStreamReader(
//					System.in));
//			String imageName = bf.readLine();
//			File input = new File(imageName);
//			setImage(ImageIO.read(input));
//		} catch (IOException ie) {
//			System.out.println("Error:" + ie.getMessage());
//		}
	}

	public void paint(Graphics g) {
		super.paint(g);
		if (getImage() != null) {
			g.drawImage(getImage(), 0, 0, (int)Math.min(this.getPreferredSize().getWidth(), getImage().getWidth()), (int)Math.min(this.getPreferredSize().getHeight(), getImage().getHeight()), null);
		}
	}

	public void setImage(BufferedImage image) {
		this.image = image;
		this.updateUI();
	}

	public BufferedImage getImage() {
		return image;
	}
}